package com.contract.management.web;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.contract.management.domain.CommJpaRepository;

@Controller
@RequestMapping("/api")
@ResponseBody
public class ApiController {
	
	@Autowired
	private CommJpaRepository repo;
	
	@RequestMapping("/getContractStatus/{no}")
	public Map<String, Object> getContractStatus(@PathVariable String no) {
		Map<String, Object> map = new HashMap<>();
		Object[] objs = repo.queryOne("select curNode.id, curNode.name from Contract c where no = ?0", no);
		if(objs == null) {
			map.put("code", -1);
			map.put("msg", "无此合同");
		} else {
			map.put("code", objs[0]);
			map.put("msg", objs[1]);
		}
		
		return map;
	}
}
